package com.lagou.dockerdemo.controller;

import com.lagou.dockerdemo.entity.TbStudent;
import com.lagou.dockerdemo.service.StudentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author jinshanzhang
 * @version 1.0
 * @description
 * @date 2021/12/16 5:51 下午
 */
@RestController
public class StudentController {

    @Resource
    private StudentService studentService;

    @PostMapping("/addStudent")
    public Integer addStudent(@RequestBody TbStudent tbStudent){
        return studentService.addStudent(tbStudent);
    }

    @PostMapping("/updateStudent")
    public String updateStudent(@RequestBody TbStudent tbStudent){
        studentService.updateStudent(tbStudent);
        return "SUCCESS";
    }

    @DeleteMapping("/deleteStudent/{studentId}")
    public String deleteStudent(@PathVariable(name = "studentId") Integer studentId){
        studentService.deleteStudent(studentId);
        return "SUCCESS";
    }

    @GetMapping("/getStudent/{studentId}")
    public String getStudent(@PathVariable(name = "studentId") Integer studentId){
        TbStudent tbStudent = studentService.selectSingleStudent(studentId);
        return tbStudent.toString();
    }
}
